package com.xxx.controller;

import com.xxx.HelloProto;
import com.xxx.HelloServiceGrpc;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    /**
     * 注解中的值要和配置文件中的保持一致
     * grpc.client.grpc-server.address=static://localhost:9000
     * grpc.client 和 .addressh之间是自定义的 注解中和配置文件的要保持一致
     */
    @GrpcClient("grpc-server")
    private HelloServiceGrpc.HelloServiceBlockingStub helloServiceBlockingStub;

    @GetMapping("hello")
    public String hello(String name) {
        System.out.println(name);
        HelloProto.HelloRequest helloRequest = HelloProto.HelloRequest.newBuilder().setName(name).build();
        HelloProto.HelloResponse helloResponse = helloServiceBlockingStub.hello(helloRequest);
        return helloResponse.getResult();
    }
}
